<template>
  <div>
    <div ref="box" style="width:400px;height:400px;" />
    <!-- <el-button type="primary">获取数据</el-button> -->
  </div>

</template>

<script>
import axios from 'axios'
import pieData from '@/views/dashboard/components/pie/pieData'
import * as Echarts from 'echarts'
export default {
  name: 'VueAdminTemplateMasterPie',

  data() {
    return {
      list: []
    }
  },

  mounted() {
    this.echarts = Echarts.init(this.$refs.box)
    this.echarts.setOption(pieData)
    this.time = setInterval(() => {
      this.getpeiData()
    }, 3000)
  },
  created() {

  },
  destroyed() {
    clearInterval(this.time)
    this.time = null
  },

  methods: {
    async getpeiData() {
      const { data } = await axios.get('/mock/echarts/pie')
      console.log(data)
      this.list = data.data.list
      console.log(pieData.series[0].data[0].value)
      console.log(this.list[0].count)
      pieData.series[0].data[0].value = this.list[0].count
      pieData.series[0].data[0].name = this.list[0].title
      pieData.series[0].data[1].name = this.list[1].title
      pieData.series[0].data[1].value = this.list[1].count
      pieData.series[0].data[2].name = this.list[2].title
      pieData.series[0].data[2].value = this.list[2].count
      pieData.series[0].data[3].name = this.list[3].title
      pieData.series[0].data[3].value = this.list[3].count
      pieData.series[0].data[4].name = this.list[4].title
      pieData.series[0].data[4].value = this.list[4].count
      this.echarts.setOption(pieData)
    }
  }

}

</script>

<style lang="scss" scoped>

</style>
